#!/usr/bin/perl
use strict;
use warnings;
use autodie;

my $name;

if (-d $ARGV[0]) {
opendir my $dirh, $ARGV[0] or die "Error: cannot open $ARGV[0]: $!\n";


foreach (readdir $dirh) {
	if (/^([a-zA-Z0-9\-]+)_[ATGCatgc]+_(L[\d][\d][\d])_R1_([\d][\d][\d])\.(fastq|fq)(\.gz)?/ || /^([a-zA-Z0-9\-]+)_[sS]\d+_(L[\d][\d][\d])_R1_([\d][\d][\d])\.(fastq|fq)(\.gz)?/ || /^([a-zA-Z0-9\-]+)_[Rr]1\.(fastq|fq)(\.gz)?/) {
		$name=$1;
		print $name;
	}
}


closedir $dirh;

}else{
	my $str="$ARGV[0]";
	if($str =~ /^([a-zA-Z0-9\-]+)_[ATGCatgc]+_(L[\d][\d][\d])_R1_([\d][\d][\d])\.(fastq|fq)(\.gz)?/ || /^([a-zA-Z0-9\-]+)_[sS]\d+_(L[\d][\d][\d])_R1_([\d][\d][\d])\.(fastq|fq)(\.gz)?/ || /^([a-zA-Z0-9\-]+)_[Rr]1\.(fastq|fq)(\.gz)?/) {
		$name=$1;
		print $name;
	}
}
